package com.krain.ddbb.activity;



import android.content.Intent;
import android.support.annotation.IntegerRes;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.krain.corelibrary.util.BaseActivityManager;
import com.krain.ddbb.R;
import com.krain.ddbb.base.BaseActivity;
import com.krain.ddbb.entity.AppApi;
import com.krain.ddbb.entity.BaseEntity;
import com.krain.ddbb.entity.UserAccountBean;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.App;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_withdraw)
public class WithdrawActivity extends BaseActivity {


    @ViewById(R.id.act_account_tv_money)
    TextView tv_money;
    @ViewById(R.id.act_withdraw_et_money)
    EditText editText;
    @Extra("money")
    String money;

    public static void jumpTothisActivity(BaseActivity activity,String money) {
        Intent intent = new Intent(activity, WithdrawActivity_.class);
        intent.putExtra("money",money);
        activity.startActivity(intent);
    }

    @Override
    protected String getToolbarTitle() {
        return "提现";
    }



    @AfterViews
    void afterView(){
        tv_money.setText(String.valueOf(money));
    }


    @Click(R.id.act_login_btn_submit)
    void widthDrawSubmit(){
        if (TextUtils.isEmpty(editText.getText())){
            baseUtil.showSnackBar(mContext,"请输入金额");
        }else if (Double.parseDouble(editText.getText().toString())> Double.parseDouble(money)){
            baseUtil.showSnackBar(mContext,"提现金额超限");
        }else {
            showProgressDialog();
            withDraw();
        }
    }

    @Background
    void withDraw(){
        BaseEntity entity = AppApi.getsInstance(mContext).widthDraw(app.getmUserinfo().getAccess_token(),String.valueOf(money));
        if (entity != null){
            finish();
        }
        dismissProgressDialog();
    }




}
